#include<cstdio>
#include<cstring>
const int N=1100;
int f[N][N],v[N],w[N];
int n,m,t;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++)
			scanf("%d",&v[i]);
		for(int i=1;i<=n;i++)
			scanf("%d",&w[i]);
		memset(f,0,sizeof(0));
		for(int i=1;i<=n;i++)
			for(int j=0;j<=m;j++)
			{
				f[i][j]=f[i-1][j];
				if(j-w[i]>=0&&f[i-1][j-w[i]]+v[i]>f[i][j])
					f[i][j]=f[i-1][j-w[i]]+v[i];
			}
		printf("%d\n",f[n][m]);
	}
	return 0;
}
